Learning Flex Basics (Part 1): Creating Your First Flex Application
Table of Contents
- Introduction
- A Brief Overview of Macromedia Flex
- Building the Application
- Create the Application Object
- Add a Panel for the Application Layout
- Add a Label for the View Header
- Add an Array of Objects to Define the Coffee Blends
- Add a ComboBox to Display the Coffee Blends
- Add a Text Control to Display the Description
- Add a Button to Add a Coffee Blend to the Shopping Cart
- Add a List Control for the Shopping Cart
- Add a Script to Handle the Button Click Event
- Complete Code Listing for firstapp.mxml
- Where to Go From Here
Add an Array of Objects to Define the Coffee Blends
The data model for this application is an array of objects that you build directly into the application using the Array and Object elements. Each of the objects has two properties, label and data, which you define as subtags in the Objects. This data structure corresponds to the dataProvider form used by controls like the ComboBox and List, which you use later in this tutorial.
These controls can use more complex data objects, but since you build the data model manually here, you use the simple form. The general syntax you use is:
<mx:Array id="identifier">
<mx:Object>
<label>literal string</label>
<data>another literal string</data>
</mx:Object>
</mx:Array>
The id attribute is available for nearly all Flex classes, and
you use it to provide a unique identifier for an instance of the class.
You need not provide an explicit id value unless you plan to refer
to the object in data bindings or ActionScript.
Placement of faceless elements such an array is up to you, but it is good practice to place them the top of the application, above visual elements.
- Inside the Application block, before the Panel, add the following array of objects:
<mx:Array id="coffeeArray"> <mx:Object> <label>Red Sea</label> <data>Smooth and fragrant</data> </mx:Object> <mx:Object> <label>Andes</label> <data>Rich and pungent</data> </mx:Object> <mx:Object> <label>Blue Mountain</label> <data>Delicate and refined</data> </mx:Object> </mx:Array>